package com.hymjweb.demo.hymj.finance_manage.invoice_register.detail.controller;

import com.hymjweb.demo.framework.result.BaseResultMap;
import com.hymjweb.demo.framework.sys.BaseController;
import com.hymjweb.demo.framework.sys.SysConstant;
import com.hymjweb.demo.hymj.finance_manage.invoice_register.detail.service.CwInvoiceRegisterDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/pages/finance_manage/invoice_register/detail")
public class CwInvoiceRegisterDetailController extends BaseController {

    @Autowired
    private CwInvoiceRegisterDetailService cwInvoiceRegisterDetailService;


    @RequestMapping("/saveInvoiceCode")
    @ResponseBody
    public Object saveInvoiceCode(@RequestBody Map param) throws Exception {

        if (param == null && param.isEmpty()) {
            throwException("发票码保存参数错误!");
        }

        BaseResultMap baseResultMap = new BaseResultMap();
        baseResultMap.setOk(true);
        baseResultMap.setMessage("发票号码保存成功!");

        int affectRows = cwInvoiceRegisterDetailService.saveInvoiceCode(param);

        if (affectRows <= SysConstant.INT_ZERO) {
            baseResultMap.setOk(false);
            baseResultMap.setMessage("发票号码保存失败!");
        }

        return baseResultMap;
    }


}
